// 寻找两个正序数组的中位数

let findMedianSortedArrays = function (nums1, nums2) {
  let ary = nums1.concat(nums2).sort((a, b) => a - b);
  let len = ary.length;
  let mid = 0;
  let midIdxOdd = (len + 1) / 2 - 1; // 奇数索引
  let midIdxEven = len / 2 - 1; // 偶数索引
  if (len % 2 === 0) { // 偶数
    mid = (ary[midIdxEven] + ary[midIdxEven + 1]) / 2;
  } else { // 奇数
    mid = ary[midIdxOdd];
  }
  return mid;
};

findMedianSortedArrays([1, 2], [3, 4]);